package body Util is

    function Dim (Largeur, Hauteur : Natural) return Dimension is
    begin
        return (Largeur, Hauteur);
    end Dim;
    
    function "<" (A,B : Dimension) return Boolean is
    begin
        return (Get_Largeur(A) <= Get_Largeur(B)) and
               (Get_Hauteur(A) <= Get_Hauteur(B));
    end "<";
    
    function Get_Largeur (D : Dimension) return Natural is
    begin
        return D.Largeur;
    end Get_Largeur;

    function Get_Hauteur (D : Dimension) return Natural is
    begin
        return D.Hauteur;
    end Get_Hauteur;

    procedure Set_Largeur (D: in out Dimension;L:in Natural) is 
    begin
       D.Largeur := L;
    end Set_Largeur;
    
    procedure Set_Hauteur (D: in out Dimension;H:in Natural) is
    begin
       D.Hauteur := H;   
    end Set_Hauteur;
    
    function Surface (D: Dimension) return Natural is
    begin
        return D.Largeur * D.Hauteur;
    end Surface;
        
    function ToString (D: Dimension) return String is
    begin
		return "(" & Natural_To_Str(D.Largeur) & "x" & Natural_To_Str(D.Hauteur) & ")";
    end ToString;

	function Str_To_Char(S : String) return Character is
		C : String (1..1) := S;
	begin
		return C(1);
	end Str_To_Char;

	function Char_To_Str(C : Character) return String is
		S : String (1..1);
	begin
		S(1) := C;
		return S;
	end Char_To_Str;
	
	function Natural_To_Str(N : Natural) return String is
		Taille : Natural := Natural'Image(N)'Length;
	begin
		return Natural'Image(N)(2..Taille);
	end Natural_To_Str;
	
	function Get_Kbd(Question : String) return String is
	   Buffer : String(1..255);
	   Taille_Buff : Natural;
	begin
	   Ada.Text_Io.Put(Question & " ? ");
	   Ada.Text_Io.Skip_Line;
	   Ada.Text_Io.Get_Line(Buffer, Taille_Buff);
	   return Buffer(1..Taille_Buff);
	end Get_Kbd;
	
	function Get_Kbd(Question : String) return Integer is
	   Ret : Integer;
	begin
	   Ada.Text_Io.Put(Question & " ? ");
	   Ada.Integer_Text_Io.Get(Ret);
	   return Ret;
	end Get_Kbd;
	
	function Get_Kbd(Question : String) return Character is
	   Ret : Character;
	begin
	   Ada.Text_Io.Put(Question & " ? ");
	   Ada.Text_Io.Get(Ret);
	   return Ret;
	end Get_Kbd;
end Util;